package org.shaka.db.sqlbuilder.sql;

import java.util.Collections;
import java.util.List;

import org.shaka.db.sqlbuilder.component.Column;
import org.shaka.db.sqlbuilder.component.Table;

import com.google.common.collect.Lists;

public class SqlTable implements SqlAsPartial {
    private String as;
    private Table table;

    public SqlTable(Table table, String as) {
        this.table = table;
        this.as = as;
    }

    public String getAs() {
        return as;
    }

    public String asPartial() {
        return String.format("%s AS %s", table.name(), as);
    }

    public SqlColumn column(Column column) {
        return new SqlColumn(column, as);
    }

    public List<SqlColumn> columns(Column... columns) {
        List<SqlColumn> result = Lists.newArrayList();
        if (columns.length > 0) {
            for (Column column : columns) {
                result.add(new SqlColumn(column, as));
            }
        } else {
            for (Column column : table.columns()) {
                result.add(new SqlColumn(column, as));
            }
        }
        return result;
    }

    public Table getTable() {
        return table;
    }

    @Override
    public boolean hasParams() {
        return false;
    }

    @Override
    public List<Object> params() {
        return Collections.emptyList();
    }
}
